﻿using _8.Base64FileEncryptor;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.IO;

namespace Base64Encryptor.Test
{
    [TestClass()]
    public class Base64StreamEncryptorTest
    {        
        [TestMethod()]
        public void EncryptDecryptTest()
        {
            string text = "Ala bala nica deba maika mu kakvo da izmislq !@#$#444#%#!_$123&$^5-ofcFGFHSW%T$6 eto izmislih go dobre che ne sam super tap a samo napolovina super tap";

            string tempFileName1 = Path.GetTempFileName();

            using (TextWriter tempFileWriter = new StreamWriter(tempFileName1))
            {
                tempFileWriter.Write(text);
            }

            string tempFileName2 = Path.GetTempFileName();

            using (TextReader reader = new StreamReader(tempFileName1))
            {                
                using (TextWriter writer = new StreamWriter(tempFileName2))
                {                    
                    Base64StreamEncryptor.Encrypt(reader, writer);                    
                }
            }

            string tempFileName3 = Path.GetTempFileName();

            using (TextReader reader = new StreamReader(tempFileName2))
            {                
                using (TextWriter writer = new StreamWriter(tempFileName3))
                {
                    Base64StreamEncryptor.Decrypt(reader, writer);
                }
            }

            string decryptedText ;
            using (var decryptedFile = new StreamReader(tempFileName3))
            {
                decryptedText = decryptedFile.ReadToEnd();
            }

            File.Delete(tempFileName1);
            File.Delete(tempFileName2);
            File.Delete(tempFileName3);

            Assert.AreEqual(text, decryptedText);            
        }
    }
}
